C++ std::filesystem::create | 您所在的位置:网站首页 › create or replace directory › C++ std::filesystem::create |
之前在使用std::filesystem::create_directories的过程中踩到一个坑,在SO上翻到了一个讨论,但较简略: 接下来展开讨论我的调研结果,供大家参考。 首先看下create_directories的定义。这个函数顾名思义就是递归创建路径,类似mkdir -p。注意返回值是这么定义的: Return valuetrue if a directory was created for the directory p resolves to, false otherwise.关于异常或者说带ec参数的overload,是这么定义的: The overload taking a std::error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.翻译一下就是create_directories会返回true,如果p指定的目录的确被创建了;其它情况返回false(包括这种情况:p所指定的目录已存在,没有被创建),ec中会保留系统调用的错误码。上测试代码 #include #include int main(int args, char** argv) { std::error_code ec; std::string path{"a/b/c"}; std::cout |
CopyRight 2018-2019 实验室设备网 版权所有 |